import asyncio

from aiohttp import ClientSession
from anti_useragent import UserAgent as ua
from loguru import logger

import config


def get_headers(): return config.HEADERS.copy()


async def newsletter_kuroro(worker: str, q: asyncio.Queue) -> None:
    while not q.empty():
        email = await q.get()

        headers = get_headers()
        headers["User-Agent"] = ua().random

        async with ClientSession(headers=headers) as session:
            resp = await session.post(
                "https://kuroro-utils.onrender.com/contacts",
                json={
                    "email": email,
                    'list': 'general'
                }
            )



        if resp.status == 200:
            logger.success(
                f"{worker} {email}... - successfully registered!")
        else:
            logger.error(f"{worker} - {email}... - {await resp.text()}")
            continue
